import storage from '../../utils/storage';
import { State } from '../../interface/state';
import { menuList } from '../../api/user';
import help from '../../utils/common';

const state:State = {
  userInfo: {
    adminId: null,
    truename: '',
  } || storage.getItem('userinfo'),
  menu: [],
};

const actions = {
  // 获取菜单
  async getMenuList({ commit, state: State }) {
    // 异步获取菜单
    const result = await menuList();
    console.log(result.menu);
    const menuLists = help.fillMenuRouter(data.menu);
  },
};

const mutations = {
  setUserInfo(state: State, userInfo: any) {
    storage.setItem('userinfo', userInfo);
    state.userInfo = userInfo;
  },
  saveMenu(state: State, menu:object[]) {
    storage.setItem('menu', menu);
    state.menu = menu;
  },
};
export default {
  namespaced: true,
  state,
  actions,
  mutations,
};